<template>
  <div class="dashboard-container">
    <div class="app-container">
      <PageTools>
        <span>本月: 发送双份奖金</span>
        <template #right>
          <el-button type="warning" size="small">excel导入</el-button>
          <el-button type="danger" size="small">excel导出</el-button>
          <el-button type="primary" size="small">新增员工</el-button>
        </template>
      </PageTools>
      <!-- 员工列表 -->
      <el-card style="margin-top: 10px;">
        <el-table border :data="list">
          <el-table-column label="序号" type="index" sortable="" />
          <el-table-column label="姓名" prop="username" sortable="" />
          <el-table-column label="工号" prop="workNumber" sortable="" />
          <!-- <el-table-column label="聘用形式" prop="formOfEmployment" sortable="">
            <template v-slot="{row}">
              {{ formatHireType(row.formOfEmployment) }}
            </template>
          </el-table-column> -->
          <el-table-column label="聘用形式" prop="formOfEmployment" sortable="" :formatter="formatHireType" />
          <!-- formatter 的作用专门用于控制格式化列的数据  -->
          <el-table-column label="部门" prop="departmentName" sortable="" />
          <el-table-column label="入职时间" prop="timeOfEntry" sortable="" />
          <el-table-column label="账户状态" prop="enableState" sortable="" />
          <el-table-column label="操作" sortable="" fixed="right" width="280">
            <template>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">转正</el-button>
              <el-button type="text" size="small">调岗</el-button>
              <el-button type="text" size="small">离职</el-button>
              <el-button type="text" size="small">角色</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>

        </el-table>
        <!-- 分页组件 -->
        <div style="height: 60px; margin-top: 10px">
          <el-pagination :total="total" :current-page="queryParams.page" :page-size="queryParams.size" layout="prev, pager, next" @current-change="handleCurrentChange" />
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { reqGetEmployeeList } from '@/api/employees.js'
import types from '@/api/constant/employees.js'
export default {
  name: 'Employees',
  data () {
    return {
      // 聘用形式
      hireType: types.hireType,
      // 列表总数
      total: 0,
      // 员工列表数据
      list: [],
      // 查询参数
      queryParams: {
        page: 1,
        size: 10
      }
    }
  },
  created () {
    this.loadEmpList()
  },
  methods: {
    // 聘用形式
    formatHireType ({ formOfEmployment: type }) {
      const info = this.hireType.find(item => parseInt(item.id) === parseInt(type))
      if (info) {
        return info.value
      } else {
        return '其他'
      }
    },
    // formatHireType (type) {
    //   const info = this.hireType.find(item => parseInt(item.id) === parseInt(type))
    //   if (info) {
    //     return info.value
    //   } else {
    //     return '其他'
    //   }
    // },
    // 分页处理
    handleCurrentChange (index) {
      this.queryParams.page = index
      this.loadEmpList()
    },
    // 加载员工列表数据
    async loadEmpList () {
      const ret = await reqGetEmployeeList(this.queryParams)
      if (ret.code === 10000) {
        this.list = ret.data.rows
        this.total = ret.data.total
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
